﻿''' <summary>
''' Provides extension methods to the <see cref="String">String</see> object.
''' </summary>
''' <revisions>
'''   <revision date="11/02/2008" author="Chad Green" version="1.0.0.0">Initial Development</revision>
''' </revisions>
Public Module ObjectExtensions

  ''' <summary>
  ''' Formats the specified <paramref name="value">value</paramref> as a currency.
  ''' </summary>
  ''' <param name="value">The value to convert.</param>
  ''' <returns>The value of <paramref name="value">value</paramref> formatted as a currency.</returns>
  ''' <example>
  '''   <para>The following examples populate a textbox with an amount formatted as currency.</para>
  '''   <code language="vb">
  '''     Public Sub PopulateAwardAmount(ByVal AwardAmount As Decimal)
  '''       txtAwardAmount.Text = AwardAmount.ToCurrency
  '''     End Sub
  '''   </code>
  '''   <code language="c#">
  '''     public void PopulateAwardAmount(decimal AwardAmount)
  '''     {
  '''     	txtAwardAmount.Text = AwardAmount.ToCurrency
  '''     }
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function ToCurrency(ByVal value As Object) As String
    Return ToCurrency(value, True)
  End Function

  ''' <summary>
  ''' Formats the specified <paramref name="value">value</paramref> as a currency.
  ''' </summary>
  ''' <param name="value">The value to convert.</param>
  ''' <param name="displayAsCurrency">Indicates whether the returned value should be displayed as a currency value or not.</param>
  ''' <returns>The value of <paramref name="value">value</paramref> formatted as a currency.</returns>
  ''' <example>
  '''   <para>The following examples populate a label with an amount formatted as currency.</para>
  '''   <code language="vb">
  '''     Public Sub PopulateAwardAmount(ByVal AwardAmount As Decimal)
  '''       lblAwardAmount.Text = AwardAmount.ToCurrency(True)
  '''     End Sub
  '''   </code>
  '''   <code language="c#">
  '''     public void PopulateAwardAmount(decimal AwardAmount)
  '''     {
  '''     	lblAwardAmount.Text = AwardAmount.ToCurrency(true)
  '''     }
  '''   </code>
  ''' </example>
  ''' <revisions>
  '''   <revision date="11/02/2008" author="Chad Green" version="1.00.000">Initial Development</revision>
  ''' </revisions>
  <Extension()> Public Function ToCurrency(ByVal value As Object, _
                                           ByVal displayAsCurrency As Boolean) As String
    If IsNumeric(value) = True Then
      If displayAsCurrency = True Then
        Return FormatCurrency(value)
      Else
        Return FormatNumber(value)
      End If
    Else
      Return "N/A"
    End If
  End Function

End Module